package 链表;

public class getKthFromEnd {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode p=head,q;
        int count=1;
        while (p!=null){
            ++count;
            p=p.next;
            if(count==k) break;
        }
        p=p.next;
        q=head;
        while (p!=null){
            q=q.next;
            p=p.next;
        }
        return q;
    }
}
